import http from '@/utils/http'
import type { PageQuery, PageRes } from '@/types/api'

const BASE_URL = '/task/info'

export interface ProjectStats {
  id: number
  name: string
  taskCount: number
}

export interface TaskStats {
  id: number
  name: string
  taskTestLogTotal: number
}

export interface UserWorkloadStats {
  userId: number
  userName: string
  testHour: number
  prepHour: number
  overtimeHour: number
}

export interface Result<T = any> {
  code: number;
  message: string;  
  data: T;
  success: boolean; 
  timestamp: number;
}

export interface TaskLogReq {
  projectId?: number | null  // 可选的项目ID
  startDate?: string  // 可选的开始日期
  endDate?: string    // 可选的结束日期
}

export interface DeviceLogResp{
  deviceId:number
  deviceName:string
  deviceDay:string
  testHour: number
  prepHour: number
}

export interface AllProjectWorkloadStatsResp {
  projectId: number
  projectName: string
  testHour: number
  prepHour: number
  overtimeHour: number
  totalHour: number
}

export interface LocWorkloadStats {
  locId: number
  locName: string
  testHour: number
  prepHour: number
  workDays: number
}

/**
 * 获取所有项目工时统计（仅需要时间段参数）
 */
export function listAllProjectWorkloadStats(params: TaskLogReq) {
  return http.post<Result<{ data: AllProjectWorkloadStatsResp[] }>>(`/task/projectInfo/allProjectWorkloadStats`, params)
}

/**
 * 获取项目列表统计
 */
export function listProjectStats() {
  return http.get<Result<ProjectStats>>(`/task/projectInfo/projectStats`)
}

/**
 * 获取项目下的任务统计
 */
export function listTaskStats(projectId: number) {
  return http.post<Result<TaskStats>>(`${BASE_URL}/taskStats/${projectId}`)
}

/**
 * 获取任务下的试验人员工时统计
 */
export function listUserWorkloadStats(params: TaskLogReq) {
  return http.post<Result<{ data: UserWorkloadStats[] }>>(`/task/testLog/userWorkloadStats`, params)
}

/**
 * 获取任务下的试验地点工时统计
 */
export function listLocWorkloadStats(params: TaskLogReq) {
  return http.post<Result<{ data: LocWorkloadStats[] }>>(`/task/testLog/locWorkloadStats`, params)
}
